package com.poisonh.unifiedauth.ui.fragment;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.poisonh.unifiedauth.R;
import com.poisonh.unifiedauth.dialog.PassWdDialogFragment;
import com.poisonh.unifiedauth.model.BusinessCard;
import com.poisonh.unifiedauth.ui.IdentityCardActivity;
import com.poisonh.unifiedauth.utils.ConstantUitls;
import com.poisonh.unifiedauth.utils.GlideCircleTransform;
import com.poisonh.unifiedauth.utils.ToastUtils;

/**
 * Created by wish30_2 on 2017/2/28.
 */

@SuppressLint("ValidFragment")
public class BusinuessCardFragment extends BaseCardFragment implements View.OnClickListener{

    private BusinessCard mBusinessCard;

    private CardView cardView;
    private TextView mUnVerity;
    private TextView mName;
    private TextView mCellphone;
    private TextView mEMail;
    private TextView mCompany;
    private ImageView mMyHead;

    private ImageView mCellphoneImg;
    private ImageView mEMailImg;
    private ImageView mCompanyImg;

    private OnClickFramgmentItemListener mListener;


    public BusinuessCardFragment(BusinessCard businessCard) {
        super(R.layout.fragment_business_card);
        this.mBusinessCard = businessCard;
    }
    @Override
    protected void bindData(View view, Bundle savedInstanceState) {


        cardView = (CardView) view.findViewById(R.id.card_view);
        cardView.setOnClickListener(this);

        mName = (TextView) view.findViewById(R.id.name);
        mCellphone = (TextView) view.findViewById(R.id.cellphone);
        mEMail = (TextView) view.findViewById(R.id.email);
        mCompany = (TextView) view.findViewById(R.id.company);
        mMyHead = (ImageView) view.findViewById(R.id.head_img);

        mCellphoneImg = (ImageView) view.findViewById(R.id.cellphone_img);
        mEMailImg = (ImageView) view.findViewById(R.id.email_img);
        mCompanyImg = (ImageView) view.findViewById(R.id.company_img);

        mName.setText(mBusinessCard.getName());
       // mCellphone.setText(mBusinessCard.getMobile());
       // mEMail.setText(mBusinessCard.getEmail());
        // mCompany.setText(mBusinessCard.getCompany());

        String strMobile = mBusinessCard.getMobile();
        if(strMobile==null||"".equals(strMobile)){
            mCellphoneImg.setVisibility(View.INVISIBLE);
            mCellphone.setText("");
        }else{
            mCellphoneImg.setVisibility(View.VISIBLE);
            mCellphone.setText(strMobile);
        }

        String strEmail = mBusinessCard.getEmail();
        if(strEmail==null||"".equals(strEmail)){
            mEMailImg.setVisibility(View.INVISIBLE);
            mEMail.setText("");
        }else{
            mEMailImg.setVisibility(View.VISIBLE);
            mEMail.setText(strEmail);

        }

        String strCompany = mBusinessCard.getCompany();
        if(strCompany==null||"".equals(strCompany)){
            mCompanyImg.setVisibility(View.INVISIBLE);
            mCompany.setText("");
        }else{
            mCompanyImg.setVisibility(View.VISIBLE);
            mCompany.setText(strCompany);
        }

       // Glide.with(this).load(ConstantUitls.REQUEDT_IMG_URL +mBusinessCard.getHeadImg()).into(mMyHead);
        Glide.with(this).load(ConstantUitls.REQUEDT_IMG_URL+ mBusinessCard.getHeadImg()).transform(new GlideCircleTransform(getActivity())).into(mMyHead);

    }

    /**
     * 发短信
     */
    private   void  sendSMS(String webUrl){
        String smsBody = "姓名: " + mBusinessCard.getName() + "\n" +
                "手机: " + mBusinessCard.getMobile() + "\n" +
                "邮箱: " + mBusinessCard.getEmail()+ "\n" +
                "地址: " + mBusinessCard.getCompany() + "\n" +
                "年轮，您的身份管理专家！"+ "\n" +
                webUrl;
        Uri smsToUri = Uri.parse( "smsto:" );
        Intent sendIntent =  new  Intent(Intent.ACTION_VIEW, smsToUri);
        //sendIntent.putExtra("address", "123456"); // 电话号码，这行去掉的话，默认就没有电话
        //短信内容
        sendIntent.putExtra( "sms_body", smsBody);
        sendIntent.setType( "vnd.android-dir/mms-sms" );
        startActivityForResult(sendIntent, 1002);
    }

    @Override
    public void onClick(View view) {
        mListener.onClickFramgmentItem();
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mListener = (OnClickFramgmentItemListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString() + " must onClickFramgmentItemListener");
        }
    }

    public  interface  OnClickFramgmentItemListener{
        public void onClickFramgmentItem();
    }
}
